<template>
  <!-- 视频组件 -->
  <div>
    <div class="widths">
      <div
        v-if="mask_img" class="mask" 
      >
        <img class="frame-path" :src="videoData.poster_url" alt="">
        <img @mouseleave="pause" @mouseenter="play" class="play" src="//sf1-scmcdn-tos.pstatp.com/goofy/oe/platform_web/static/image/play.svg?f3db861d10cf31d0ff0778b1b4331ba9" alt="">
        <div class="long-time">
          {{ videoData.duration.toFixed(2) }}
        </div>
      </div>
      <!-- :controls="controls" -->
      <video v-else muted="muted" autoplay onMouseOver="this.play()" onMouseOut="this.pause()" @mouseleave="pause" class="video_class" >
        <source :src="videoData.url" type="video/mp4" />
      </video>
    </div>
  </div>
</template>

<script>
export default {
  props:{
    value:{
      type:Object
    }
  },
  data(){
    return {
      videoData:this.value,
      mask_img: true 
    }
  },
  watch:{
    value:function (params) {
      this.videoData = params
    }
  },
  created(){
    // console.info(this.value,'value')
  },
  methods:{
    play(){
      this.controls = true
      this.mask_img = false
    },
    pause(){
      this.mask_img = true
      this.controls = false
    }
  }
}
</script>

<style lang="less" scoped>
.widths{
  width: 100%;
  height: 100%;
  position: relative;
  // 视频跟随父元素大小
  .video_class{
    width: 100%;
    height: 100%;
    object-fit: fill;
  }
  // 遮罩
  .mask{
    width: 100%;
    height: 100%;
    position: relative;
    .play{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
    }
    .long-time{
      width: 50px;
      height: 30px;
      font-size: 14px;
      text-align: center;
      position: absolute;
      top: 0px;
      left: 0px;
      color: white;
      padding: 0 5px;
      background-color: rgba(0, 0, 0, .6);
      border-radius: 5px;
      // border: 1px solid white;
    }
    .frame-path{
      width: 100%;
      height: 100%;
      object-fit: fill;
    }
    
    & :hover{
      cursor: pointer;
    }
  }
}
</style>